package com.example.administrator.myapplication;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v7.widget.AppCompatEditText;
import android.util.AttributeSet;


/**
 * Created by Administrator on 2018/1/3.
 */

public class LinedEditText extends AppCompatEditText {
    private Rect mRect;
    private Paint mPaint;


    public LinedEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        mRect = new Rect();
        mPaint = new Paint();
        mPaint.setColor(Color.GRAY);

    }

    @Override
    protected void onDraw(Canvas canvas){

        int count = getLineCount();
        Paint paint  = mPaint;
        Rect r = mRect;
        //设置每一行格式
        for(int i = 0;i<count;i++)
        {
            //取得每一行的基准y坐标，并将每一行的界限值填写到R中
            int baseline = getLineBounds(i,r);
            canvas.drawLine(r.left,baseline+5,r.right,baseline+5,paint);

        }
        super.onDraw(canvas);
    }
}
